Popular Searches
Popular Course Categories
Popular Courses

Multi-Select Dropdown

Multi-Select Dropdown

Dropdowns & Advanced Elements

Multi-Select Dropdown in Selenium WebDriver

A Multi-Select Dropdown is a dropdown list that allows users to select more than one option at the same time. In HTML, a standard multi-select dropdown is generally created using the <select> element with the multiple attribute. Selenium WebDriver provides the Select class to interact with standard HTML select elements.

In Selenium Java, the Select class provides methods for selecting options by visible text, value, or index, as well as methods for deselecting options and retrieving the currently selected options.

Course Resource: Selenium Training Course

Course Demo: Register for Selenium Course Demo


1. What is a Multi-Select Dropdown?

A multi-select dropdown is a form control that allows the user to choose multiple options from a single list. Unlike a normal single-select dropdown, where selecting one option replaces the previous selection, a multi-select dropdown can maintain several selected options simultaneously.

For example, an employee registration form may allow a user to select multiple skills such as Java, Selenium, SQL, and API Testing.

<select id="skills" name="skills" multiple>

    <option value="java">Java</option>

    <option value="selenium">Selenium</option>

    <option value="sql">SQL</option>

    <option value="api">API Testing</option>

</select>

 

2. Single Select vs Multi-Select Dropdown

FeatureSingle SelectMulti-Select
Multiple optionsNormally one optionMultiple options can be selected
HTML attributeNo multiple attributeUses multiple
Selenium Select classSupportedSupported
Deselect methodsNot applicableSupported
getAllSelectedOptions()Normally returns one selected optionCan return multiple selected options
isMultiple()Returns falseReturns true

 

3. HTML Structure of a Multi-Select Dropdown

The important difference between a normal select dropdown and a multi-select dropdown is the multiple attribute.

<select id="courses" multiple>

    <option value="java">Java</option>

    <option value="selenium">Selenium</option>

    <option value="python">Python</option>

    <option value="sql">SQL</option>

</select>

The presence of the multiple attribute indicates that more than one option can be selected. Selenium's Select.isMultiple() checks whether the select element supports multiple selections.

 

4. Why Multi-Select Dropdowns are Important in Testing

Multi-select controls are commonly used in registration forms, filters, product configuration, employee skills, permissions, categories, course selection, reporting systems, and search forms.

  • They allow testing multiple selections in a single field.
  • They require verification of all selected values.
  • They allow testing of deselection functionality.
  • They can be used to validate minimum and maximum selection rules.
  • They are useful for testing form submission with multiple values.

 

5. Selenium Select Class

Selenium provides the org.openqa.selenium.support.ui.Select class for interacting with standard HTML <select> elements. The class provides methods for selecting, deselecting, and retrieving options.

import org.openqa.selenium.support.ui.Select;

 

6. Important Rule: Select Class Works with <select>

The Selenium Select class should be used for standard HTML <select> elements. It does not automatically work with custom dropdowns created using elements such as <div>, <li>, buttons, or JavaScript UI components.

<select id="skills" multiple>

    <option value="java">Java</option>

    <option value="selenium">Selenium</option>

</select>

 

7. Creating a Select Object

First locate the multi-select dropdown using a Selenium locator and then pass the resulting WebElement to the Select constructor.

WebElement dropdown = driver.findElement(By.id("skills"));

Select select = new Select(dropdown);

 

8. Complete Basic Setup

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

 

public class MultiSelectExample {

    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://example.com");

 

        WebElement dropdown = driver.findElement(By.id("skills"));

        Select select = new Select(dropdown);

 

        driver.quit();

    }

}

 

9. Checking Whether the Dropdown Supports Multiple Selection

The isMultiple() method determines whether the select element supports selecting multiple options.

boolean multiple = select.isMultiple();

 

System.out.println("Is Multi-Select: " + multiple);

Expected output:

Is Multi-Select: true

 

10. Validating a Multi-Select Dropdown

if (select.isMultiple()) {

    System.out.println("This is a multi-select dropdown.");

} else {

    System.out.println("This is a single-select dropdown.");

}

 

11. Selecting Multiple Options by Visible Text

selectByVisibleText() selects an option using the text displayed to the user. For a multi-select dropdown, the method can be called repeatedly to select several options.

select.selectByVisibleText("Java");

select.selectByVisibleText("Selenium");

select.selectByVisibleText("SQL");

After execution, Java, Selenium, and SQL can all remain selected.

 

12. Selecting Multiple Options by Value

selectByValue() selects options according to the HTML value attribute.

select.selectByValue("java");

select.selectByValue("selenium");

select.selectByValue("sql");

Example HTML:

<select id="skills" multiple>

    <option value="java">Java</option>

    <option value="selenium">Selenium</option>

    <option value="sql">SQL</option>

</select>

 

13. Selecting Multiple Options by Index

selectByIndex() selects an option based on its index.

select.selectByIndex(0);

select.selectByIndex(1);

select.selectByIndex(3);

Index-based selection should be used carefully because changing the order of options in the application can affect the test.

 

14. Selecting Options Using All Three Methods

select.selectByVisibleText("Java");

select.selectByValue("selenium");

select.selectByIndex(2);

 

15. Deselecting a Selected Option

One of the major advantages of a multi-select dropdown is that selected options can be deselected. Selenium provides several deselection methods specifically for multiple-selection lists.

 

16. Deselect by Visible Text

select.deselectByVisibleText("Java");

This removes the selection from the option whose visible text matches Java.

 

17. Deselect by Value

select.deselectByValue("selenium");

This removes the selection from the option whose value attribute matches Selenium.

 

18. Deselect by Index

select.deselectByIndex(2);

 

19. Deselect All Options

The deselectAll() method clears all selected options from a multi-select dropdown.

select.deselectAll();

 

20. Selecting and Deselecting Multiple Options

select.selectByVisibleText("Java");

select.selectByVisibleText("Selenium");

select.selectByVisibleText("SQL");

 

select.deselectByVisibleText("Selenium");

Final selection:

Java

SQL

 

21. Getting All Options

The getOptions() method returns all options belonging to the select element.

List<WebElement> options = select.getOptions();

 

for (WebElement option : options) {

    System.out.println(option.getText());

}

 

22. Import for List

import java.util.List;

 

23. Printing All Dropdown Options

List<WebElement> options = select.getOptions();

 

for (WebElement option : options) {

    System.out.println("Option: " + option.getText());

}

 

24. Getting All Selected Options

The getAllSelectedOptions() method returns all options currently selected in the dropdown. For a multi-select dropdown, the returned list may contain multiple elements.

List<WebElement> selectedOptions =

        select.getAllSelectedOptions();

 

25. Printing Selected Options

List<WebElement> selectedOptions =

        select.getAllSelectedOptions();

 

for (WebElement option : selectedOptions) {

    System.out.println("Selected: " + option.getText());

}

 

26. Counting Selected Options

int selectedCount = select.getAllSelectedOptions().size();

 

System.out.println("Selected Options: " + selectedCount);

 

27. Verifying the Number of Selected Options

int expectedCount = 3;

int actualCount = select.getAllSelectedOptions().size();

 

if (actualCount == expectedCount) {

    System.out.println("Correct number of options selected.");

} else {

    System.out.println("Selection count is incorrect.");

}

 

28. Checking Whether a Particular Option is Selected

A specific option can also be located and checked using isSelected().

WebElement seleniumOption =

        driver.findElement(By.cssSelector("option[value='selenium']"));

 

if (seleniumOption.isSelected()) {

    System.out.println("Selenium is selected.");

}

 

29. Complete Multi-Select Example

import java.util.List;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

 

public class MultiSelectDropdown {

    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://example.com");

 

        WebElement dropdown =

                driver.findElement(By.id("skills"));

 

        Select select = new Select(dropdown);

 

        if (select.isMultiple()) {

            select.selectByVisibleText("Java");

            select.selectByVisibleText("Selenium");

            select.selectByVisibleText("SQL");

 

            List<WebElement> selected =

                    select.getAllSelectedOptions();

 

            for (WebElement option : selected) {

                System.out.println(option.getText());

            }

        }

 

        driver.quit();

    }

}

 

30. Multi-Select Dropdown Execution Flow

Open Browser

      ↓

Open Application

      ↓

Locate <select> Element

      ↓

Create Select Object

      ↓

Check isMultiple()

      ↓

Select Option 1

      ↓

Select Option 2

      ↓

Select Option 3

      ↓

Verify Selected Options

      ↓

Deselect Option if Required

      ↓

Submit Form

      ↓

Verify Result

      ↓

Close Browser

 


31. Selecting Options from a List

When the expected options are stored in Java collections, a loop can be used to select multiple values.

String[] skills = {"Java", "Selenium", "SQL"};

 

for (String skill : skills) {

    select.selectByVisibleText(skill);

}

 

32. Selecting Options from an ArrayList

List<String> skills = List.of(

    "Java",

    "Selenium",

    "SQL"

);

 

for (String skill : skills) {

    select.selectByVisibleText(skill);

}

 

33. Selecting Options Dynamically

Dynamic selection is useful when the expected values come from test data rather than being hard-coded individually.

String[] expectedSkills = {

    "Java",

    "Selenium",

    "API Testing",

    "SQL"

};

 

for (String skill : expectedSkills) {

    select.selectByVisibleText(skill);

}

 

34. Verifying Multiple Selected Values

List<WebElement> selectedOptions =

        select.getAllSelectedOptions();

 

for (WebElement option : selectedOptions) {

    String selectedText = option.getText();

 

    System.out.println(

        "Selected Option: " + selectedText

    );

}

 

35. Verifying Expected Selection

List<String> expected = List.of(

    "Java",

    "Selenium",

    "SQL"

);

 

List<WebElement> selected =

        select.getAllSelectedOptions();

 

for (WebElement option : selected) {

    System.out.println(option.getText());

}

 

36. Multi-Select Dropdown with TestNG Assertion

import static org.testng.Assert.assertTrue;

 

WebElement option =

        driver.findElement(

            By.cssSelector("option[value='java']")

        );

 

select.selectByValue("java");

 

assertTrue(

    option.isSelected(),

    "Java should be selected"

);

 

37. Verifying Number of Selected Options with TestNG

import static org.testng.Assert.assertEquals;

 

select.selectByValue("java");

select.selectByValue("selenium");

select.selectByValue("sql");

 

int actual =

        select.getAllSelectedOptions().size();

 

assertEquals(

    actual,

    3,

    "Three options should be selected"

);

 

38. Verifying Multi-Select Capability with TestNG

assertTrue(

    select.isMultiple(),

    "Dropdown should support multiple selections"

);

 

39. Deselecting and Verifying

select.selectByValue("java");

select.selectByValue("selenium");

 

select.deselectByValue("java");

 

WebElement javaOption =

        driver.findElement(

            By.cssSelector("option[value='java']")

        );

 

assertFalse(

    javaOption.isSelected(),

    "Java should be deselected"

);

 

40. Clearing All Selections

select.deselectAll();

 

int count =

    select.getAllSelectedOptions().size();

 

System.out.println("Selected count: " + count);

 

41. Multi-Select Dropdown Using XPath

WebElement dropdown =

    driver.findElement(

        By.xpath("//select[@id='skills']")

    );

 

Select select = new Select(dropdown);

 

select.selectByVisibleText("Java");

select.selectByVisibleText("Selenium");

 

42. Multi-Select Dropdown Using CSS Selector

WebElement dropdown =

    driver.findElement(

        By.cssSelector("select#skills")

    );

 

Select select = new Select(dropdown);

 

select.selectByValue("java");

select.selectByValue("selenium");

 

43. Multi-Select Dropdown Using Name Locator

WebElement dropdown =

    driver.findElement(By.name("skills"));

 

Select select = new Select(dropdown);

 

select.selectByVisibleText("Java");

select.selectByVisibleText("SQL");

 

44. Multi-Select Dropdown Using Class Name

WebElement dropdown =

    driver.findElement(By.className("skills-dropdown"));

 

Select select = new Select(dropdown);

 

45. Selecting All Options

Java's Selenium Select API does not provide a standard selectAll() method. A common approach is to retrieve all options with getOptions() and select them one by one.

List<WebElement> options = select.getOptions();

 

for (WebElement option : options) {

    if (!option.isSelected()) {

        option.click();

    }

}

Alternatively, for controlled test data, selecting known options individually with selectByVisibleText() or selectByValue() is generally clearer.

 

46. Selecting All Options by Index

List<WebElement> options = select.getOptions();

 

for (int i = 0; i < options.size(); i++) {

    select.selectByIndex(i);

}

 

47. Why Visible Text is Often Useful

Visible text is often easier to understand in test scripts because it corresponds directly to what the user sees.

select.selectByVisibleText("Selenium");

This can make test cases easier to read and maintain.

 

48. Why Value is Useful

The value attribute can be useful when visible text changes but the application's underlying value remains stable.

select.selectByValue("selenium");

 

49. Why Index Should be Used Carefully

Index-based selection depends on the position of an option. If the application inserts, removes, or reorders options, the same index may refer to a different option.

select.selectByIndex(2);

For maintainable automation, visible text or value can often be preferable when those attributes are stable.

 

50. Handling Pre-Selected Options

A multi-select dropdown may load with one or more options already selected.

List<WebElement> selected =

    select.getAllSelectedOptions();

 

for (WebElement option : selected) {

    System.out.println(

        "Initially selected: " + option.getText()

    );

}

 

51. Testing Pre-Selected Values

List<WebElement> selected =

    select.getAllSelectedOptions();

 

if (selected.size() > 0) {

    System.out.println(

        "Dropdown contains pre-selected options."

    );

}

 

52. Testing Empty Selection

A multi-select control can potentially have zero selected options, depending on the application's HTML and validation rules.

select.deselectAll();

 

if (select.getAllSelectedOptions().isEmpty()) {

    System.out.println("No options are selected.");

}

 

53. Validating Minimum Selection

int selectedCount =

    select.getAllSelectedOptions().size();

 

if (selectedCount >= 2) {

    System.out.println(

        "Minimum selection requirement satisfied."

    );

} else {

    System.out.println(

        "At least two options must be selected."

    );

}

 

54. Validating Maximum Selection

int selectedCount =

    select.getAllSelectedOptions().size();

 

if (selectedCount <= 5) {

    System.out.println(

        "Maximum selection requirement satisfied."

    );

} else {

    System.out.println(

        "Too many options are selected."

    );

}

 

55. Testing Duplicate Selection

A test can verify what happens when the same option is selected more than once by the automation code.

select.selectByValue("java");

select.selectByValue("java");

The test should verify the resulting selected state rather than assuming that a duplicate selection creates duplicate selected entries.

 

56. Multi-Select Dropdown with Form Submission

select.selectByVisibleText("Java");

select.selectByVisibleText("Selenium");

select.selectByVisibleText("SQL");

 

driver.findElement(By.id("submit")).click();

 

57. Verifying Submitted Data

String result =

    driver.findElement(

        By.id("result")

    ).getText();

 

System.out.println(

    "Submitted Skills: " + result

);

 

58. Real-World Example: Skills Selection

Consider an employee registration form containing a Skills multi-select dropdown.

<select id="skills" multiple>

    <option value="java">Java</option>

    <option value="selenium">Selenium</option>

    <option value="sql">SQL</option>

    <option value="api">API Testing</option>

    <option value="python">Python</option>

</select>

Automation:

Select skills =

    new Select(driver.findElement(By.id("skills")));

 

skills.selectByValue("java");

skills.selectByValue("selenium");

skills.selectByValue("sql");

 

59. Real-World Example: Course Selection

WebElement courseDropdown =

    driver.findElement(By.id("courses"));

 

Select courses = new Select(courseDropdown);

 

courses.selectByVisibleText("Selenium");

courses.selectByVisibleText("Java");

courses.selectByVisibleText("API Testing");

 

60. Real-World Example: Product Categories

WebElement categories =

    driver.findElement(By.id("categories"));

 

Select selectCategories =

    new Select(categories);

 

selectCategories.selectByValue("electronics");

selectCategories.selectByValue("laptops");

selectCategories.selectByValue("accessories");

 

61. Real-World Example: User Permissions

WebElement permissions =

    driver.findElement(By.id("permissions"));

 

Select select =

    new Select(permissions);

 

select.selectByVisibleText("Read");

select.selectByVisibleText("Write");

select.selectByVisibleText("Reports");

 

62. Multi-Select Dropdown in Page Object Model

In the Page Object Model, dropdown interactions can be encapsulated inside page classes so that test cases remain readable.

public class RegistrationPage {

 

    private WebDriver driver;

 

    private By skillsDropdown =

        By.id("skills");

 

    public RegistrationPage(WebDriver driver) {

        this.driver = driver;

    }

 

    public void selectSkills(String... skills) {

 

        Select select =

            new Select(

                driver.findElement(skillsDropdown)

            );

 

        for (String skill : skills) {

            select.selectByVisibleText(skill);

        }

    }

}

 

63. Using the Page Object Method

RegistrationPage page =

    new RegistrationPage(driver);

 

page.selectSkills(

    "Java",

    "Selenium",

    "SQL"

);

 

64. Reusable Multi-Select Utility Method

public static void selectMultipleByText(

        WebDriver driver,

        By locator,

        String... values) {

 

    Select select =

        new Select(driver.findElement(locator));

 

    for (String value : values) {

        select.selectByVisibleText(value);

    }

}

 

65. Calling the Utility Method

selectMultipleByText(

    driver,

    By.id("skills"),

    "Java",

    "Selenium",

    "SQL"

);

 

66. Utility Method for Deselecting Values

public static void deselectMultipleByText(

        WebDriver driver,

        By locator,

        String... values) {

 

    Select select =

        new Select(driver.findElement(locator));

 

    for (String value : values) {

        select.deselectByVisibleText(value);

    }

}

 

67. Utility Method to Clear Multi-Select

public static void clearMultiSelect(

        WebDriver driver,

        By locator) {

 

    Select select =

        new Select(driver.findElement(locator));

 

    select.deselectAll();

}

 

68. Explicit Wait Before Interacting

If the dropdown is loaded dynamically, an explicit wait can be useful before interacting with it.

import java.time.Duration;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

 

WebDriverWait wait =

    new WebDriverWait(

        driver,

        Duration.ofSeconds(10)

    );

 

WebElement dropdown =

    wait.until(

        ExpectedConditions.visibilityOfElementLocated(

            By.id("skills")

        )

    );

 

Select select = new Select(dropdown);

 

69. Waiting for Dropdown to be Clickable

WebElement dropdown =

    wait.until(

        ExpectedConditions.elementToBeClickable(

            By.id("skills")

        )

    );

 

Select select = new Select(dropdown);

 

70. Multi-Select Dropdown and JavaScript Applications

Modern applications frequently use custom dropdown components rather than native HTML <select> elements. In such cases, the Selenium Select class is not appropriate because it is designed for standard select/option elements.

 

71. Native Multi-Select vs Custom Multi-Select

FeatureNative Multi-SelectCustom Multi-Select
HTML<select multiple>Often div/button/li based
Selenium Select classYesNo
Options<option>Custom elements
SelectionSelect APINormal WebElement interactions
DeselectSelect APIApplication-specific controls

 

72. Example of a Custom Multi-Select

<div class="dropdown">

    <button>Select Skills</button>

 

    <div class="options">

        <div>Java</div>

        <div>Selenium</div>

        <div>SQL</div>

    </div>

</div>

This is not a standard <select> element. Therefore, normal Selenium locators and WebElement interactions should be used instead of Select.

 

73. Handling a Custom Multi-Select

driver.findElement(

    By.xpath("//button[text()='Select Skills']")

).click();

 

driver.findElement(

    By.xpath("//div[text()='Java']")

).click();

 

driver.findElement(

    By.xpath("//div[text()='Selenium']")

).click();

 

driver.findElement(

    By.xpath("//div[text()='SQL']")

).click();

 

74. Common Error: UnexpectedTagNameException

If the Select constructor receives an element that is not a standard <select> element, Selenium can throw an UnexpectedTagNameException. The Select class constructor expects a SELECT element.

WebElement element =

    driver.findElement(By.id("customDropdown"));

 

Select select = new Select(element);

If customDropdown is actually a div, the Select class should not be used.

 

75. Common Error: UnsupportedOperationException

Deselect operations are intended for multi-select elements. Attempting to use them on a single-select element can result in an unsupported-operation error.

select.deselectAll();

Before performing multi-selection-specific operations, verify:

if (select.isMultiple()) {

    select.deselectAll();

}

 

76. Common Error: NoSuchElementException

If Selenium cannot find an option matching the supplied text, value, or index, the operation can fail.

select.selectByVisibleText("Invalid Option");

Always verify the option's actual visible text and value in the DOM.

 

77. Common Error: StaleElementReferenceException

If the page dynamically refreshes or replaces the dropdown element after it has been located, the previously stored WebElement can become stale.

WebElement dropdown =

    driver.findElement(By.id("skills"));

 

Select select = new Select(dropdown);

 

// Application refreshes the dropdown here

 

select.selectByVisibleText("Java");

A common solution is to locate the element again after the DOM update.

 

78. Common Error: ElementNotInteractableException

This can occur when the element is present but cannot currently be interacted with. Possible causes include overlays, disabled controls, animations, or incorrect locators.

 

79. Disabled Multi-Select Dropdown

A disabled select element should not be treated as an interactive control. Before interacting with a disabled dropdown, verify its enabled state.

 

80. Checking Whether the Dropdown is Enabled

WebElement dropdown =

    driver.findElement(By.id("skills"));

 

if (dropdown.isEnabled()) {

    Select select = new Select(dropdown);

    select.selectByValue("java");

} else {

    System.out.println(

        "Dropdown is disabled."

    );

}

 

81. Handling Dynamic Options

Some applications load options after an API call or another user interaction. In these situations, locate the dropdown after it becomes available and verify that the expected options exist before selecting them.

WebDriverWait wait =

    new WebDriverWait(

        driver,

        Duration.ofSeconds(10)

    );

 

WebElement dropdown =

    wait.until(

        ExpectedConditions.visibilityOfElementLocated(

            By.id("skills")

        )

    );

 

Select select = new Select(dropdown);

 

82. Verify Option Exists Before Selecting

List<WebElement> options =

    select.getOptions();

 

boolean found = false;

 

for (WebElement option : options) {

    if (option.getText().equals("Selenium")) {

        found = true;

        break;

    }

}

 

if (found) {

    select.selectByVisibleText("Selenium");

}

 

83. Printing All Option Values

for (WebElement option : select.getOptions()) {

    System.out.println(

        "Text: " + option.getText()

    );

 

    System.out.println(

        "Value: " + option.getAttribute("value")

    );

}

 

84. Comparing Selected Options with Expected Options

List<String> expected =

    List.of("Java", "Selenium", "SQL");

 

List<String> actual =

    select.getAllSelectedOptions()

          .stream()

          .map(WebElement::getText)

          .toList();

 

System.out.println("Expected: " + expected);

System.out.println("Actual: " + actual);

 

85. Important Multi-Select Test Scenarios

  • Verify the dropdown is displayed.
  • Verify the dropdown is enabled.
  • Verify that it supports multiple selection.
  • Select one option.
  • Select two options.
  • Select several options.
  • Deselect one option.
  • Deselect multiple options.
  • Deselect all options.
  • Verify initially selected options.
  • Verify the number of selected options.
  • Verify form submission with multiple values.
  • Verify validation when no option is selected.
  • Verify minimum selection rules.
  • Verify maximum selection rules.
  • Verify dynamically loaded options.
  • Verify disabled options where applicable.

 

86. Multi-Select Dropdown Test Case Example

Test CaseActionExpected Result
TC01Open dropdownDropdown should be displayed
TC02Check multi-select capabilityisMultiple() should return true
TC03Select JavaJava should be selected
TC04Select SeleniumJava and Selenium should remain selected
TC05Select SQLThree options should be selected
TC06Deselect SeleniumSelenium should no longer be selected
TC07Deselect allNo options should remain selected
TC08Submit formSelected values should be processed correctly

 

87. Best Practices for Multi-Select Dropdown Automation

  • Use the Select class only for standard HTML <select> elements.
  • Check isMultiple() when the test specifically requires multi-selection.
  • Prefer stable visible text or value attributes over fragile indexes.
  • Use explicit waits for dynamically loaded dropdowns.
  • Verify selected options instead of assuming selection succeeded.
  • Use reusable utility methods for repeated dropdown operations.
  • Keep test data separate from automation logic where possible.
  • Use Page Object Model for maintainable frameworks.
  • Handle custom dropdowns separately from native select elements.
  • Use deselectAll() when the test requires a clean selection state.

 

88. Common Mistakes

  • Using Select on a div-based custom dropdown.
  • Assuming every dropdown supports multiple selections.
  • Using incorrect option values.
  • Depending heavily on index values when the order is dynamic.
  • Not verifying selected options.
  • Calling deselection methods on a single-select dropdown.
  • Ignoring dynamically loaded options.
  • Not checking whether the dropdown is disabled.
  • Using hard-coded waits instead of explicit waits.
  • Not clearing previous selections between independent test cases.

 

89. Multi-Select Dropdown Automation Checklist

  • Identify whether the control is a native <select>.
  • Check for the multiple attribute.
  • Locate the dropdown.
  • Create the Select object.
  • Verify isMultiple().
  • Select required options.
  • Verify selected options.
  • Deselect required options.
  • Verify deselection.
  • Clear selections when required.
  • Submit the form.
  • Verify the resulting application state.

 

90. Multi-Select Dropdown Quick Revision

MethodPurpose
isMultiple()Checks whether multiple selections are supported
selectByVisibleText()Selects by displayed text
selectByValue()Selects by value attribute
selectByIndex()Selects by index
getOptions()Returns all options
getAllSelectedOptions()Returns all selected options
getFirstSelectedOption()Returns the first selected option
deselectByVisibleText()Deselects by displayed text
deselectByValue()Deselects by value
deselectByIndex()Deselects by index
deselectAll()Clears all selected options

 

91. Important Interview Question: What is a Multi-Select Dropdown?

A multi-select dropdown is a standard HTML select element that supports selecting more than one option, typically by using the multiple attribute.

 

92. Interview Question: Which Selenium Class is Used?

The Selenium Java Select class from org.openqa.selenium.support.ui.Select is used to interact with standard HTML select elements.

 

93. Interview Question: How Do You Select Multiple Options?

Select select = new Select(

    driver.findElement(By.id("skills"))

);

 

select.selectByVisibleText("Java");

select.selectByVisibleText("Selenium");

select.selectByVisibleText("SQL");

 

94. Interview Question: How Do You Check Whether it is Multi-Select?

boolean result = select.isMultiple();

If the result is true, the select element supports multiple selections.

 

95. Interview Question: How Do You Get All Selected Options?

List<WebElement> selected =

    select.getAllSelectedOptions();

 

96. Interview Question: How Do You Deselect All Options?

select.deselectAll();

This operation is intended for a multi-select element.

 

97. Interview Question: Can Select Class Handle Custom Dropdowns?

No. The Select class is intended for standard HTML <select> and <option> elements. Custom dropdowns implemented using other HTML elements need normal Selenium element interactions.

 

98. Interview Question: What is the Difference Between selectByValue and selectByVisibleText?

MethodSelection BasisExample
selectByValue()HTML value attributeselect.selectByValue("java");
selectByVisibleText()Text displayed to userselect.selectByVisibleText("Java");
selectByIndex()Option indexselect.selectByIndex(0);

 

99. Mini Project: Employee Skills Multi-Select Form

Build an automation test for an employee registration page containing a multi-select Skills dropdown.

Requirements:

  • Open the employee registration page.
  • Locate the Skills dropdown.
  • Verify that it supports multiple selection.
  • Select Java.
  • Select Selenium.
  • Select SQL.
  • Verify that three options are selected.
  • Deselect SQL.
  • Verify that two options remain selected.
  • Clear all selections.
  • Verify that no options are selected.

 

100. Mini Project Implementation

import java.util.List;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.Select;

 

public class EmployeeSkillsTest {

    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();

 

        try {

            driver.get("https://example.com/employee");

 

            WebElement dropdown =

                driver.findElement(By.id("skills"));

 

            Select skills =

                new Select(dropdown);

 

            if (!skills.isMultiple()) {

                throw new RuntimeException(

                    "Skills dropdown is not multi-select"

                );

            }

 

            skills.selectByVisibleText("Java");

            skills.selectByVisibleText("Selenium");

            skills.selectByVisibleText("SQL");

 

            List<WebElement> selected =

                skills.getAllSelectedOptions();

 

            System.out.println(

                "Selected Count: " + selected.size()

            );

 

            for (WebElement option : selected) {

                System.out.println(

                    "Selected: " + option.getText()

                );

            }

 

            skills.deselectByVisibleText("SQL");

 

            System.out.println(

                "After deselection: " +

                skills.getAllSelectedOptions().size()

            );

 

            skills.deselectAll();

 

            System.out.println(

                "Final selection count: " +

                skills.getAllSelectedOptions().size()

            );

 

        } finally {

            driver.quit();

        }

    }

}

 

101. Project Execution Flow

Employee Registration Page

          ↓

Locate Skills Dropdown

          ↓

Create Select Object

          ↓

Check isMultiple()

          ↓

Select Java

          ↓

Select Selenium

          ↓

Select SQL

          ↓

Verify 3 Selected Options

          ↓

Deselect SQL

          ↓

Verify 2 Selected Options

          ↓

Deselect All

          ↓

Verify 0 Selected Options

          ↓

Close Browser

 

102. Advanced Validation Example

if (!select.isMultiple()) {

    throw new AssertionError(

        "Expected a multi-select dropdown"

    );

}

 

select.selectByValue("java");

select.selectByValue("selenium");

select.selectByValue("sql");

 

List<WebElement> selected =

    select.getAllSelectedOptions();

 

if (selected.size() != 3) {

    throw new AssertionError(

        "Expected 3 selected options but found "

        + selected.size()

    );

}

 

for (WebElement option : selected) {

    System.out.println(

        "Verified: " + option.getText()

    );

}

 

103. Multi-Select Dropdown Automation Strategy

Identify Control

      ↓

Is it <select>?

      ↓

    Yes

      ↓

Create Select Object

      ↓

Is multiple supported?

      ↓

    Yes

      ↓

Select Required Values

      ↓

Verify Selection

      ↓

Deselect if Required

      ↓

Verify Final State

 

104. Native Select vs Custom Dropdown Decision

Dropdown Found

      ↓

Inspect HTML

      ↓

Is element <select>?

   ↙             ↘

 Yes              No

 ↓                 ↓

Use Select       Use WebElement

Class            interactions

 ↓                 ↓

Select/Deselect  Click options

methods          manually

 

105. Practical Tips for Interview and Real Projects

  • Always inspect the HTML before deciding how to automate a dropdown.
  • Look specifically for the <select> tag.
  • Look for the multiple attribute when multiple selection is expected.
  • Remember that Select is a Selenium support class, not a generic solution for every dropdown.
  • Know the difference between selecting and deselecting methods.
  • Know how to retrieve all selected options.
  • Know how to validate the number of selected options.
  • Be able to explain native versus custom dropdowns.
  • Use explicit waits when dropdown content is dynamically loaded.
  • Use Page Object Model and utility methods in large automation frameworks.

 

106. Complete Cheat Sheet

// Locate dropdown

WebElement element =

    driver.findElement(By.id("skills"));

 

// Create Select object

Select select = new Select(element);

 

// Check multi-select

select.isMultiple();

 

// Select by text

select.selectByVisibleText("Java");

 

// Select by value

select.selectByValue("java");

 

// Select by index

select.selectByIndex(0);

 

// Get all options

select.getOptions();

 

// Get selected options

select.getAllSelectedOptions();

 

// Get first selected option

select.getFirstSelectedOption();

 

// Deselect by text

select.deselectByVisibleText("Java");

 

// Deselect by value

select.deselectByValue("java");

 

// Deselect by index

select.deselectByIndex(0);

 

// Deselect all

select.deselectAll();

 

107. Key Points to Remember

  • Multi-select dropdown: Allows multiple options to remain selected.
  • HTML: Usually implemented with <select multiple>.
  • Selenium class: Select.
  • Multiple check: isMultiple().
  • Select methods: selectByVisibleText(), selectByValue(), selectByIndex().
  • Selected options: getAllSelectedOptions().
  • Deselect methods: deselectByVisibleText(), deselectByValue(), deselectByIndex(), deselectAll().
  • Custom dropdown: Do not use the Select class unless the underlying control is a standard <select>.
  • Best practice: Verify the selected state after performing the action.

 

108. Final Conclusion

Multi-select dropdown automation is an important Selenium WebDriver skill because many real-world applications allow users to select multiple values from a single field. For standard HTML select elements, Selenium's Select class provides convenient methods to select options by visible text, value, and index, retrieve selected options, and deselect individual or all options.

The most important concept is to first determine whether the application uses a native <select multiple> control or a custom JavaScript-based dropdown. Native select controls can be handled with Select, while custom dropdowns should be automated using appropriate Selenium element interactions.

 

109. Course Resources

Selenium Training: https://www.justacademy.co/course-detail/selenium-training

Register for Course Demo: https://www.justacademy.co/register-for-course-demo

whatsapp